package us.icitap.cm.business.entities;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import org.eclipse.persistence.annotations.Customizer;

import us.icitap.cm.utils.MyCustomizer;

@Entity
@Customizer(MyCustomizer.class)
@Table(name="ITEM", schema="MPC")
public class Item implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 8420784503974968711L;


	@Id
	@Column(insertable=false, updatable = false)
	private Integer id;
	

	@OneToOne
	@JoinColumn(name="ID",nullable=false)
	private AppEntity appEntity;
	
	@ManyToOne
	@JoinColumn(name="ITEM_CLASSIFICATION_ID")
	private AppList itemClassification;
	
	@ManyToOne
	@JoinColumn(name="ITEM_TYPE_ID")
	private AppList itemType;
	
	
	@Column(length=150)
	private String name;
	
	@Column(length=300)
	private String description;
	
	@Column(length=50)
	private String value;
	
	@Column(length=500)
	private String notes;

	public Item() {
		// TODO Auto-generated constructor stub
	}
	
	public Item(Item item) {
		this.description = item.getDescription();
		this.itemClassification = item.getItemClassification();
		this.itemType = item.getItemType();
		this.name = item.getName();
		this.notes = item.getNotes();
		this.value = item.getValue();
		
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public AppEntity getAppEntity() {
		return appEntity;
	}

	public void setAppEntity(AppEntity appEntity) {
		this.appEntity = appEntity;
	}


	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public String getNotes() {
		return notes;
	}

	public void setNotes(String notes) {
		this.notes = notes;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Item other = (Item) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}

	public boolean myEquals(Object obj) {
		return true;
	}
	public AppList getItemClassification() {
		return itemClassification;
	}

	public void setItemClassification(AppList itemClassification) {
		this.itemClassification = itemClassification;
	}

	public AppList getItemType() {
		return itemType;
	}

	public void setItemType(AppList itemType) {
		this.itemType = itemType;
	}

	@Override
	public String toString() {
		if(itemClassification != null){
			if(itemType != null){
				if(name != null) return name + ", " + itemType.getTag() + ", " + itemClassification.getTag();
				else return  itemType.getTag() + ", " + itemClassification.getTag();
			}
			else return name + ", "  + itemClassification.getTag();		
		}
		else if(name != null) return name;
		return "Sendi nr. " + id;
	}
}
